 //var wxCode=getURLParameter('code');
var wxCode=getURLPara('code');
// alert(pp)

var vm =  new Vue({
	  el : "#app",
      data : {
	  login_type:0,//0为正常登录，1为注册，2为验证码登录，3为忘记密码。
      code_show:false,
      yz_code:'获取验证码',
      yz_time:60,
      grpCode:'',
      forwordPage:"",//跳转页面
      timer_ctrl:'',//全局定时器
      login_tel:'',//正常0登录电话
      login_pass:'',//正0常登录密码
      regis_tel:'',//注册手机号
      yz_tel_num:'',//获取验证码登录时验证码输入的手机号
      yz_tel_num_3:'',//获取忘记密码验证码输入的手机号
      yz_tel_code_3:'',//重置密码的验证码
      yz_tel_code_1:'',//注册密码的验证码
      yz_tel_code:'',//获取的验证码
      new_password:'',//注册的新密码
      wx_code:'',//微信code
      agree_show:false,
      falg:false,
      pass_word_one:'',//第一次输入的重置密码
      pass_word_two:'',//第二次输入的重置密码
      login_tel:''//正常登录手机号
			},
  created:function(){ 
    this.wx_code=wxCode;
      //alert('微信code是'+this.wx_code);
      this.grpCode = _lSGet('grpCode');
      this.forwordPage = _lSGet('forwordPage');


  },
  mounted:function(){


  },
  methods:{
    yzm_login:function(){


    },
    //tips:function(tip){//封装提示
    //
    //layer.open({
    //content: tip
    //,skin: 'msg'
    //,time: 2 //2秒后自动关闭
    //});
    //},
    agree_ok:function(){
        var that=this;
        if(that.falg==false){
        that.agree_show=true;
        that.falg=true;
        } else  if(that.falg=true){
        that.agree_show=false;
        that.falg=false;
        }
    },
    go_login:function(){
       var that=this;
       this.yzTelNumber(this.login_tel);
       if (this.login_tel&&(/^1[34578]\d{9}$/.test(this.login_tel))){//输入手机号格式正确
       var params = {};
       params.mobile = this.login_tel;
       params.password = this.login_pass;
       sendRequest('/wxLogin/pwdLogin', params, function(res) {//登录
             console.log('opop');
             console.log(res);
             if(res.status==1){
                 _lSSaveOrUpdate( 'token', res.data.opInfo.token );
                 _lSSaveOrUpdate( 'opId', res.data.opInfo.id );
                 _lSSaveOrUpdate( 'openId', res.data.opInfo.openId );
                 _lSSaveOrUpdate( 'userId', res.data.opInfo.userId );
                 _lSSaveOrUpdate( 'levelName', res.data.opInfo.levelName );//会员等级
                 _lSSaveOrUpdate( 'userName', res.data.opInfo.userName );//会员名
                 _lSSaveOrUpdate( 'userName', res.data.opInfo.userName );
                 _lSSaveOrUpdate( 'urls', JSON.stringify(res.data.urls) );
                 var pp=  _lSGet('token');
                 console.log(pp);
                 if (that.forwordPage==null||that.forwordPage == '') {
                     window.location.href = indexUrl + '/index.html?_t=' + Math.random();
                    // window.location.replace( indexUrl + '/index.html?_t=' + Math.random())
                 } else {
                    // window.location.href = indexUrl + that.forwordPage + '?_t=' + Math.random();
                     window.location.replace( indexUrl + that.forwordPage + '?_t=' + Math.random());
                 }
            }
            if(res.status==-1){
                tips(res.returnMsg);
            }
        });
       } else{
        tips('手机号输入不正确')
      }
    },
    yzTelNumber: function (userTelNum) {
        var that = this;
          if (!userTelNum) {
             // Toast('电话号码不能为空');
          }else if (!(/^1[34578]\d{9}$/.test(userTelNum))) {
             // Toast('电话号码格式错误');
          }
      },
    go_login_t1:function(){//type类型1，注册
         //alert(this.new_password);
         //alert(this.yz_tel_code_1);
         //this.login_type=0;
         var params = {};
         params.mobile = this.regis_tel;//手机号
         params.password = this.new_password;// 填写的密码
         params.verificationCode = this.yz_tel_code_1;// 填写的验证码
         params.code = this.wx_code;// 微信code
         params.grpCode = this.grpCode;// grpCode
         var that=this;
         sendRequest('/wxRegister/register', params, function(res) {
            console.log('kkkkk');
            //console.log(params);
            console.log(res);
             tips(res.returnMsg);
            if(res.status==1){//注册成功
            //_lSSaveOrUpdate( 'token', res.data );
                var paramss = {};
                paramss.mobile = this.regis_tel;
                paramss.password =  this.new_password;
                sendRequest('/wxLogin/pwdLogin', paramss, function(res) {//登录
                    console.log('opop');
                    console.log(res);
                    if(res.status==1){
                        _lSSaveOrUpdate( 'token', res.data.opInfo.token );
                        _lSSaveOrUpdate( 'openId', res.data.opInfo.openId );
                        _lSSaveOrUpdate( 'opId', res.data.opInfo.id );
                        _lSSaveOrUpdate( 'userId', res.data.opInfo.userId );
                        _lSSaveOrUpdate( 'levelName', res.data.opInfo.levelName );//会员等级
                        _lSSaveOrUpdate( 'userName', res.data.opInfo.userName );//会员名
                        _lSSaveOrUpdate( 'userName', res.data.opInfo.userName );
                        //var pp=  _lSGet('token');
                        //console.log(pp);
                       // window.location.href=indexUrl+'/index.html?_t=' + Math.random();
                        if (that.forwordPage == '') {
                            window.location.replace = indexUrl + '/index.html?_t=' + Math.random();
                        } else {
                           // window.location.href = indexUrl + that.forwordPage + '?_t=' + Math.random();
                            window.location.replace( indexUrl + that.forwordPage + '?_t=' + Math.random());
                        }
                    }
                    //if(res.status==-1){
                    //    tips(res.returnMsg);
                    //}
                });

            tips(res.returnMsg);
            that.login_type=0;
      
            } else{
                tips(res.returnMsg);
            }
        });
    },      
    go_login_t2:function(){//type类型2，验证码登录
        if (!(/^1[34578]\d{9}$/.test(this.yz_tel_num))){
            tips('手机号格式不正确');
            return;
        }
        var params = {};
        params.mobile = this.yz_tel_num;
        params.verificationCode = this.yz_tel_code;// 填写的验证码
        var that=this;
        sendRequest('/wxLogin/verificationCodeLogin', params, function(res) {
            console.log('kkkkk')
            console.log(res);
            if(res.status==1){
                _lSSaveOrUpdate( 'token', res.data.opInfo.token );
                _lSSaveOrUpdate( 'openId', res.data.opInfo.openId );
                _lSSaveOrUpdate( 'userId', res.data.opInfo.userId );
                _lSSaveOrUpdate( 'userName', res.data.opInfo.userName );
              // window.location.href=indexUrl+'/index.html?_t=' + Math.random();
                if (this.forwordPage == '') {
                    window.location.href = indexUrl + '/index.html?_t=' + Math.random();
                } else {
                    //window.location.href = indexUrl + that.forwordPage + '?_t=' + Math.random();
                    window.location.replace( indexUrl + that.forwordPage + '?_t=' + Math.random());
                }
            }
            if(res.status==-1){
                tips(res.returnMsg)
            }

     });
    },

    go_login_t3:function(){//type类型3，重置密码并登录
        if (!(/^1[34578]\d{9}$/.test(this.yz_tel_num_3))){
            tips('手机号格式不正确');
            return;
         }
         if(this.pass_word_one!=this.pass_word_two){
             tips('两次密码输入不相同，请重新输入')
         }else{
            var params = {};
            params.mobile = this.yz_tel_num_3;
            params.password = this.pass_word_one;
            params.confirmPassword = this.pass_word_one;//和上面一样
            params.verificationCode = this.yz_tel_code_3;//验证码

            var that=this;
            sendRequest('/forgetPassword/changePassword', params, function(res) {
                console.log('kkkkk');
                console.log(res);
                if(res.status==1){
                    //_lSSaveOrUpdate( 'token', res.data.opInfo.token );
                    //_lSSaveOrUpdate( 'openId', res.data.opInfo.openId );
                    //_lSSaveOrUpdate( 'userId', res.data.opInfo.userId );
                    //_lSSaveOrUpdate( 'userName', res.data.opInfo.userName );
                    var paramss = {};
                    paramss.mobile = params.mobile;
                    paramss.password =   params.password;
                    sendRequest('/wxLogin/pwdLogin', paramss, function(res) {//登录
                        console.log('opop');
                        console.log(res);
                        if(res.status==1){
                            _lSSaveOrUpdate( 'token', res.data.opInfo.token );
                            _lSSaveOrUpdate( 'openId', res.data.opInfo.openId );
                            _lSSaveOrUpdate( 'opId', res.data.opInfo.id );
                            _lSSaveOrUpdate( 'userId', res.data.opInfo.userId );
                            _lSSaveOrUpdate( 'levelName', res.data.opInfo.levelName );//会员等级
                            _lSSaveOrUpdate( 'userName', res.data.opInfo.userName );//会员名
                            _lSSaveOrUpdate( 'userName', res.data.opInfo.userName );
                            //var pp=  _lSGet('token');
                            //console.log(pp);
                            //window.location.href=indexUrl+'/index.html?_t=' + Math.random();
                            if (that.forwordPage == '') {
                                window.location.href = indexUrl + '/index.html?_t=' + Math.random();
                            } else {
                                //window.location.href = indexUrl + that.forwordPage + '?_t=' + Math.random();
                                window.location.replace( indexUrl + that.forwordPage + '?_t=' + Math.random());
                            }
                        }
                        //if(res.status==-1){
                        //    tips(res.returnMsg);
                        //}
                    });
                   //window.location.href=indexUrl+'/index.html?_t=' + Math.random();
                }
                if(res.status==-1){
                    tips(res.returnMsg);
                }
            });
        }
     },

    get_code:function(){//获取验证码 
         //this.yzTelNumber(this.yz_tel_num);
        //alert(this.yz_tel_num)
        var that=this;
        if ( (/^1[34578]\d{9}$/.test(that.yz_tel_num))|| (/^1[34578]\d{9}$/.test(that.yz_tel_num_3))|| (/^1[34578]\d{9}$/.test(that.regis_tel))){//输入手机号格式正确
            that.yz_code = "剩余" + that.yz_time + "秒";
            that.code_show=true;
            var timer = setInterval(function () {
            var time = that.yz_time - 1;
            if (that.yz_time > 1) {
            that.yz_time =time,
            that.yz_code = "剩余" + time + "秒"
            } else {
            clearInterval(timer);//清除定时器
            that.yz_time = 60,
            that.code_show=false;
            that.yz_code = "获取验证码";
                  }
              }, 1000);
            that.timer_ctrl=timer;
            //验证成功的话继续
            var params = {};

        if(that.login_type==2){//前端定义验证码登录
            //alert('2')
            params.mobile = that.yz_tel_num;
            params.type=1;//1,登录  2,注册 3,找回密码

        }
        else if(that.login_type==3){//前端定义忘记密码
            //alert(3)
            params.mobile = that.yz_tel_num_3;
            params.type=3;//1,登录  2,注册 3,找回密码
        }
        else if(that.login_type==1){//前端定义注册
            //alert(1)
            params.mobile = that.regis_tel;
            params.type=2;//1,登录  2,注册 3,找回密码

    }
        //console.log(params);
        sendRequest('/pinCode/send',params , function(res) {//发送验证码
            //console.log('opop')
            console.log(res);
             tips(res.returnMsg)
            //if(res.status=1){
                //
            //  }
        });
    } else{
      	tips('手机号格式错误')
      }
    }    
   },
    computed: {
   
  
   },
    watch:{
        login_type:function(){//清除定时器走动效果
        var that=this;
        clearInterval(that.timer_ctrl)
        that.yz_time = 60,
        that.code_show=false;
        that.yz_code = "获取验证码";
      }
   },

    components:{
  	    
  }
 




			
});